<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UserModel
 *
 * @author Marko
 */
class User_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    public function create($type, $email, $password) {
        $this->db->insert('user', array(
            'type' => $type,
            'email' => $email,
            'password' => sha1($password)
        ));
    }

    public function delete($id) {
        $this->db->where(array('id' => $id));
        $this->db->delete('users');
    }

    public function login($email, $password) {
        $this->db->select('id, email, password, type');
        $this->db->from('users');
        $this->db->where('email', $email);
        $this->db->where('password', sha1($password));
        $this->db->limit(1);

        $query = $this->db->get();

        if ($query->num_rows() == 1) {
            return $query->result();
        } else {
            return false;
        }
    }

}

?>
